﻿// Decompiled by AS3 Sorcerer 6.12
// www.as3sorcerer.com

//GUI

package 
{
    import com.gamezhero.api.as3.GamezheroDictionary;
    import com.gamezhero.api.as3.GamezheroGlobal;
    import flash.filters.GlowFilter;
    import flash.display.Sprite;
    import flash.net.SharedObject;
    import flash.display.Graphics;
    import flash.display.DisplayObject;
    import flash.events.MouseEvent;
    import com.gameallianz.api.as3.GameAllianzApiLinks;
    import flash.events.Event;
    import com.gameallianz.api.as3.GameAllianzApi;
    import flash.display.Bitmap;
    import flash.display.MovieClip;
    import com.bit101.components.Style;
    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    import com.bit101.components.Window;
    import com.bit101.components.VBox;
    import com.bit101.components.Text;
    import com.bit101.components.HBox;
    import com.bit101.components.PushButton;
    import com.gameallianz.api.as3.assets.AssetPortalLogo;
    import com.gameallianz.api.as3.assets.AssetFacebookButton;
    import com.gameallianz.api.as3.assets.AssetTwitterButton;
    import com.newgrounds.components.MedalPopup;
    import com.newgrounds.API;
    import flash.display.*;
    import com.gamezhero.api.as3.*;
    import flash.events.*;
    import com.bit101.components.*;
    import flash.net.*;
    import flash.text.*;
    import com.gameallianz.api.as3.*;
    import com.addthis.*;

    public class GUI 
    {

        public static const OUTLINE_COLOR:int = 0xEEEEEE;
        public static const INNER_COLOR:int = 0x888888;
        public static const BACK_COLOR:int = 0x333333;
        public static const MAX_X:int = 640;
        public static const MAX_Y:int = 480;
        public static const BOTTOM_Y:int = 480;
        public static const TXT_MORE_GAMES:String = GamezheroDictionary.getTranslationByName(GamezheroDictionary.MORE_GAMES).toUpperCase();
        public static const TXT_WALKTHROUGH:String = GamezheroDictionary.getTranslationByName(GamezheroDictionary.WALKTHROUGH).toUpperCase();
        public static const TXT_REPLAY:String = GamezheroDictionary.getTranslationByName(GamezheroDictionary.REPLAY).toUpperCase();
        public static const TXT_MENU:String = GamezheroDictionary.getTranslationByName(GamezheroDictionary.MAIN_MENU).toUpperCase();
        public static const TXT_CONTINUE:String = GamezheroDictionary.getTranslationByName(GamezheroDictionary.CONTINUE).toUpperCase();
        public static const TXT_SUBMIT_SCORE:String = GamezheroDictionary.getTranslationByName(GamezheroDictionary.SUBMIT_TOP_SCORE).toUpperCase();
        public static const TXT_ZONE:String = GamezheroDictionary.getTranslationByName("zone").toLocaleUpperCase();
        public static const TXT_TIME:String = GamezheroDictionary.getTranslationByName("time").toLocaleUpperCase();
        public static const TXT_ZONE_OCCUPIED:String = GamezheroDictionary.getTranslationByName("zone occupied").toLocaleUpperCase();
        public static const TXT_EXTERMINATION:String = GamezheroDictionary.getTranslationByName("extermination").toLocaleUpperCase();
        public static const TXT_SCORE:String = GamezheroDictionary.getTranslationByName("score").toLocaleUpperCase();
        public static const TXT_CLASS:String = GamezheroDictionary.getTranslationByName("class");
        public static const TXT_POWER:String = GamezheroDictionary.getTranslationByName("power");
        public static const TXT_MAX_POWER:String = GamezheroDictionary.getTranslationByName("power limit");
        public static const TXT_SHARED_LEVELS:String = GamezheroDictionary.getTranslationByName("shared-levels").toLocaleUpperCase();
        public static const TXT_TEST:String = GamezheroDictionary.getTranslationByName("test-save").toLocaleUpperCase();
        public static const TXT_EDIT:String = GamezheroDictionary.getTranslationByName("level-editor").toLocaleUpperCase();
        public static const TXT_CREATE_MICROBE:String = GamezheroDictionary.getTranslationByName("create-microbe");
        public static const TXT_CREATE_WALL:String = GamezheroDictionary.getTranslationByName("create-wall");
        public static const TXT_DELETE_MICROBE:String = GamezheroDictionary.getTranslationByName("delete-microbe");
        public static const TXT_DELETE_WALL:String = GamezheroDictionary.getTranslationByName("delete-wall");
        public static const TXT_MICROBE:String = GamezheroDictionary.getTranslationByName("microbe");
        public static const TXT_WALL:String = GamezheroDictionary.getTranslationByName("wall");
        public static const TXT_NORMAL_AI:String = GamezheroDictionary.getTranslationByName("normal-ai");
        public static const TXT_QUICK_AI:String = GamezheroDictionary.getTranslationByName("quick-ai");
        public static const TXT_INSTANT_AI:String = GamezheroDictionary.getTranslationByName("instant-ai");
        public static const TXT_DISABLE_AI:String = GamezheroDictionary.getTranslationByName("disable-ai");
        public static const TXT_GREEN:String = GamezheroDictionary.getTranslationByName("green");
        public static const TXT_RED:String = GamezheroDictionary.getTranslationByName("red");
        public static const TXT_BLACK:String = GamezheroDictionary.getTranslationByName("black");
        public static const TXT_PURPLE:String = GamezheroDictionary.getTranslationByName("purple");
        public static const TXT_NEUTRAL:String = GamezheroDictionary.getTranslationByName("neutral");
        public static const TXT_SUBMIT_LVL_HINT_OK:String = GamezheroDictionary.getTranslationByName("submit-lvl-hint-ok");
        public static const TXT_SUBMIT_LVL_HINT_ERROR:String = GamezheroDictionary.getTranslationByName("submit-lvl-hint-error");
        public static const TXT_LEVEL_NAME:String = GamezheroDictionary.getTranslationByName("level-name");
        public static const TXT_AUTHOR:String = GamezheroDictionary.getTranslationByName("author");
        public static const TXT_SUBMIT:String = GamezheroDictionary.getTranslationByName(GamezheroDictionary.SUBMIT);
        public static const TXT_CANCEL:String = GamezheroDictionary.getTranslationByName("cancel");
        public static const TXT_SAVE_LEVEL:String = GamezheroDictionary.getTranslationByName("save-level");
        public static const TXT_ERROR:String = GamezheroDictionary.getTranslationByName("error");
        public static const TXT_PLAY:String = GamezheroDictionary.getTranslationByName("play");
        public static const TXT_LEVEL_URL:String = GamezheroDictionary.getTranslationByName("share-with-friends");
        public static const TXT_LEVEL_URL_LONG1:String = GamezheroDictionary.getTranslationByName("share-level-long-1");
        public static const TXT_LEVEL_URL_LONG2:String = GamezheroDictionary.getTranslationByName("share-level-long-2");
        public static const TXT_OPEN_URL:String = GamezheroDictionary.getTranslationByName("open-link");
        public static const TXT_COPY_TO_CLIPBOARD:String = GamezheroDictionary.getTranslationByName("copy-clipboard");
        public static const TXT_ORIGINAL_GAME:String = "Tentacle Wars 1".toLocaleUpperCase();
        public static const TXT_FINAL_SCREEN:String = "Created by Lumarama";
        public static const TXT_SELECT_LEVEL:String = GamezheroDictionary.getTranslationByName("select-level");
        public static const TXT_TOP_RATED:String = GamezheroDictionary.getTranslationByName("top-rated");
        public static const TXT_LATEST:String = GamezheroDictionary.getTranslationByName("latest");
        public static const TXT_SHARED:String = "X";
        public static const TXT_PAGE:String = GamezheroDictionary.getTranslationByName("page");
        public static const TXT_OF:String = GamezheroDictionary.getTranslationByName("of");
        public static const TXT_TUTORIAL1:String = GamezheroDictionary.getTranslationByName("game-hint-1");
        public static const TXT_TUTORIAL2:String = GamezheroDictionary.getTranslationByName("game-hint-2");
        public static const TXT_GAME_HINT1:String = GamezheroDictionary.getTranslationByName("game-text-1");
        public static const TXT_GAME_HINT2:String = GamezheroDictionary.getTranslationByName("game-text-4");
        public static const TXT_GAME_HINT3:String = GamezheroDictionary.getTranslationByName("game-text-5");
        public static const URL_ORIGINAL_GAME:String = (((("http://www.gamezhero.com/online-games/strategy-games/tentaclewars-games.html?utm_campaign=" + GamezheroGlobal.gameName) + "&utm_source=") + GamezheroGlobal.domain) + "&utm_medium=tentaclewars1");
        public static const URL_SHARED_LEVEL:String = "http://www.gamezhero.com/online-games/strategy-games/tentaclewarsthepurplemenace-games.html?level_id=";
        public static const BmpBack:Class = GUI_BmpBack;
        private static const BmpTitleBack:Class = GUI_BmpTitleBack;
        private static const BmpSponsor:Class = GUI_BmpSponsor;
        private static const BUTTON_GLOW:GlowFilter = new GlowFilter(0xFFFF00, 0.5, 6, 6);
        private static const BG_COLOR:uint = 1122850;
        private static const ADD_THIS_X_DELTA:uint = 0;
        private static var m_game:Main = null;
        private static var m_parent:Sprite = null;
        private static var m_fade:Sprite = null;
        private static var m_fadeInProgress:Boolean = false;
        private static var m_fadeEnabled:Boolean = true;
        private static var m_fadeAlpha:Number = 1;
        private static var m_fadeCompleteFunc:Function = null;
        private static var m_currLevel:int = 0;
        private static var m_openLevel:int = 0;
        private static var m_currScore:int = 0;
        private static var m_totalTries:int = 0;
        private static var m_successTries:int = 0;
        private static var m_soundOn:Boolean = true;
        private static var m_items:Array = new Array();
        private static var m_sharedObj:SharedObject = null;
        private static var m_sharedLvl:SharedLevels = null;


        private static function _SafeStr_21(isLevelPassed:Boolean, time:int):Sprite
        {
            var dialogX:* = 280;
            var dialogY:* = 300;
            var dialog:Sprite = new Sprite();
            var g:Graphics = dialog.graphics;
            removeAll();
            var offsetY:int = 30;
            dialog.x = (MAX_X / 2);
            dialog.y = ((MAX_Y / 2) - offsetY);
            g.beginFill(BG_COLOR, 1);
            g.lineStyle(1, 0x555555);
            g.drawRect((-(dialogX) / 2), ((-(dialogY) / 2) + offsetY), dialogX, dialogY);
            g.endFill();
            var hdr:Sprite = createText(((isLevelPassed) ? TXT_ZONE_OCCUPIED : TXT_EXTERMINATION).toUpperCase(), 30, ((isLevelPassed) ? 5635925 : 16733525), 1, false, 0xFFFFFF, ((GamezheroDictionary.language == GamezheroDictionary.ENG) ? "header" : "translate"));
            hdr.x = 0;
            hdr.y = -80;
            dialog.addChild(hdr);
            var but:Sprite;
            but = _SafeStr_7(TXT_MENU, 0, 90, onGameMenu);
            dialog.addChild(but);
            var btn:DisplayObject = new BtnGamezhero();
            btn.scaleX = 0.8;
            btn.scaleY = 0.8;
            btn.x = (-(btn.width / 2) - 10);
            btn.y = (-(btn.height / 2) + 25);
            btn.addEventListener(MouseEvent.CLICK, _SafeStr_8);
            dialog.addChild(btn);
            return (dialog);
        }

        private static function _SafeStr_9():void
        {
            if (m_currLevel >= 0)
            {
                if (m_game)
                {
                    removeAll();
                    m_game.initLevel(m_currLevel);
                };
            };
            fade(false);
        }

        private static function _SafeStr_19(evt:MouseEvent):void
        {
            var but:Sprite;
            if (((m_game) && (evt.target is Sprite)))
            {
                but = (evt.target as Sprite);
                m_currLevel = int(but.name);
                if (m_currLevel >= 0)
                {
                    SoundMgr.playSfx(SoundMgr.BEGIN_GAME);
                    fade(true, _SafeStr_9);
                };
            };
        }

        public static function createText(str:String, size:int, color:uint, alpha:Number=1, outline:Boolean=false, outlineColor:uint=0xFFFFFF, fontName:String="default", isCentered:Boolean=true):TextSprite
        {
            return (new TextSprite(str, size, color, alpha, outline, outlineColor, fontName, isCentered));
        }

        private static function onSubmitScoreClick(evt:MouseEvent=null):void
        {
            Preloader.sendScore(0, m_currScore);
            _SafeStr_10();
        }

        public static function showInGamePanel(levelName:String, maxPower:int, time:int, testLevel:Boolean=false):void
        {
            removeByName("ingame-panel");
            var dialog:Sprite = new Sprite();
            dialog.x = 0;
            dialog.y = 0;
            dialog.name = "ingame-panel";
            var text:Sprite = createText(((((((TXT_ZONE + ": ") + levelName) + "   ") + TXT_MAX_POWER.toLocaleUpperCase()) + ": ") + maxPower), 11, 0xAAAAAA, 1, false, 0xFFFFFF, "translate");
            text.x = ((text.width / 2) + 10);
            text.y = 15;
            text.mouseEnabled = false;
            text.mouseChildren = false;
            dialog.addChild(text);
            text = createText(((TXT_TIME + ": ") + time), 10, 0xAAAAAA, 1, false, 0xFFFFFF, "translate", false);
            text.x = (MAX_X - 68);
            text.y = 25;
            text.mouseEnabled = false;
            text.mouseChildren = false;
            dialog.addChild(text);
            _SafeStr_11(dialog, false);
            var but:DisplayObject;
            if (testLevel)
            {
                but = _SafeStr_7(TXT_EDIT, 0, (MAX_Y - 15), function (e:MouseEvent):void
                {
                    m_game.initLevelEditor();
                });
                but.x = ((MAX_X - (but.width / 2)) - 10);
                dialog.addChild(but);
            }
            else
            {
                but = _SafeStr_7(TXT_WALKTHROUGH, (MAX_X - 70), (MAX_Y - 15), _SafeStr_8);
                but.name = GameAllianzApiLinks.TO_GAME_WALKTHROUGH;
                but.x = ((MAX_X - (but.width / 2)) - 10);
                dialog.addChild(but);
            };
            m_parent.addChild(dialog);
            m_items.push(dialog);
        }

        private static function _SafeStr_10():void
        {
            onGameMenu();
        }

        public static function onStartSharedLevel(levelData:String, levelId:String, levelName:String, hint:String):void
        {
            SoundMgr.playSfx(SoundMgr.BEGIN_GAME);
            fade(true, function ():void
            {
                removeAll();
                m_game.initSharedLevel(levelData, levelName, levelId);
                showInGameStatus(hint);
                fade(false);
            });
        }

        private static function fade(enable:Boolean, completeFunc:Function=null):void
        {
            if (!m_fadeInProgress)
            {
                m_fade.addEventListener(Event.ENTER_FRAME, GUI.onEnterFrame);
            };
            m_fadeEnabled = enable;
            m_fadeInProgress = true;
            m_fadeCompleteFunc = completeFunc;
        }

        private static function _SafeStr_20(event:MouseEvent):void
        {
            var but:DisplayObject = (event.target as DisplayObject);
            if (((!(but == null)) && (but.name.length > 0)))
            {
                trace(but.name);
                gotoUrl(but.name);
            };
        }

        public static function removeAll():void
        {
            var item:Sprite;
            m_sharedLvl.hideLevelsChooser();
            while (m_items.length > 0)
            {
                item = m_items.pop();
                item.parent.removeChild(item);
                _SafeStr_12(item);
                item = null;
            };
        }

        private static function _SafeStr_14(evt:MouseEvent):void
        {
            fade(true, replayLevel);
        }

        private static function onEnterFrame(event:Event):void
        {
            var done:Boolean;
            if (m_fadeInProgress)
            {
                done = false;
                m_fadeAlpha = (m_fadeAlpha + ((m_fadeEnabled) ? 0.3 : -0.1));
                if (m_fadeAlpha > 1)
                {
                    m_fadeAlpha = 1;
                    done = true;
                };
                if (m_fadeAlpha < 0)
                {
                    m_fadeAlpha = 0;
                    done = true;
                };
                m_fade.alpha = m_fadeAlpha;
                if (done)
                {
                    m_fade.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
                    m_fadeInProgress = false;
                    if (m_fadeCompleteFunc != null)
                    {
                        m_fadeCompleteFunc();
                    };
                };
            };
        }

        public static function createInterSharedLevelMenu(levelId:String, isLevelPassed:Boolean, time:int):void
        {
            SoundMgr.playSfx(((isLevelPassed) ? SoundMgr.LEVEL_PASSED : SoundMgr.LEVEL_FAILED));
            GameAllianzApi.rateLevel();
        }

        public static function createSharedLevelsMenu():void
        {
            removeAll();
            fade(false);
            var dialog:Sprite = _SafeStr_13();
            m_sharedLvl.showLevelsChooser();
            m_parent.addChild(dialog);
            m_items.push(dialog);
        }

        public static function createFinalScreen():void
        {
            removeAll();
            m_game.clearLevel();
            fade(true);
            SoundMgr.playSfx(SoundMgr.BEGIN_GAME);
            SoundMgr.musicEnable(false);
            var logo:Sprite = new Sprite();
            var bmp:Bitmap = new BmpSponsor();
            bmp.smoothing = true;
            logo.addChild(bmp);
            logo.scaleX = 0.7;
            logo.scaleY = 0.7;
            logo.x = ((MAX_X / 2) - (logo.width / 2));
            logo.y = ((MAX_Y / 2) + 30);
            m_fade.addChild(logo);
            m_items.push(logo);
            var text:Sprite = new TypingText(TXT_FINAL_SCREEN, 14, 15658666);
            text.x = ((MAX_X / 2) - 70);
            text.y = ((MAX_Y / 2) - 30);
            m_fade.addChild(text);
            m_items.push(text);
            var but:Sprite;
            but = _SafeStr_7(TXT_SUBMIT_SCORE, (MAX_X / 2), (MAX_Y - 80), function (evt:MouseEvent):void
            {
                if (m_soundOn)
                {
                    SoundMgr.musicEnable(true);
                };
                onSubmitScoreClick(evt);
            });
            m_fade.addChild(but);
            m_items.push(but);
            but = _SafeStr_7(TXT_ORIGINAL_GAME.toLocaleUpperCase(), (MAX_X / 2), (MAX_Y - 50), function (evt:MouseEvent):void
            {
                gotoUrl(URL_ORIGINAL_GAME);
                onGameMenu();
            });
            m_fade.addChild(but);
            m_items.push(but);
        }

        public static function hideHint():void
        {
            removeByName("hint");
        }

        private static function _SafeStr_17(evt:MouseEvent):void
        {
            var but:Sprite = (evt.target as Sprite);
            switch (evt.type)
            {
                case MouseEvent.ROLL_OVER:
                    but.filters = [BUTTON_GLOW];
                    return;
                case MouseEvent.ROLL_OUT:
                    but.filters = [];
                    return;
            };
        }

        public static function createInfoPopup(x:Number, y:Number, str:String, name:String="info-popup", isCentered:Boolean=true, fontSize:int=12):void
        {
            var text:TextSprite = createText(str.toUpperCase(), fontSize, 0xAAAAAA, 1, false, 0xFFFFFF, "translate", isCentered);
            text.x = x;
            text.y = y;
            text.name = name;
            var g:Graphics = text.graphics;
            var begx:Number = -3;
            var begy:Number = 0;
            if (isCentered)
            {
                begx = (-(text.width + 6) / 2);
                begy = (-(text.height) / 2);
            };
            var sizex:Number = (text.width + 10);
            var sizey:Number = text.height;
            var corner:Number = 8;
            g.beginFill(BG_COLOR, 0.9);
            g.lineStyle(1, 0x555555);
            g.moveTo(begx, begy);
            g.lineTo(begx, (begy + sizey));
            g.lineTo(((begx + sizex) - corner), (begy + sizey));
            g.lineTo((begx + sizex), ((begy + sizey) - corner));
            g.lineTo((begx + sizex), begy);
            g.lineTo(begx, begy);
            g.endFill();
            m_parent.addChild(text);
            m_items.push(text);
        }

        private static function _SafeStr_16(event:MouseEvent):void
        {
            m_soundOn = (!(m_soundOn));
            SoundMgr.musicEnable(m_soundOn);
            SoundMgr.sfxEnable(m_soundOn);
            var but:MovieClip = (event.target as MovieClip);
            but.gotoAndStop(((m_soundOn) ? 2 : 1));
        }

        public static function init(game:Main, parent:Sprite):void
        {
            Style.setStyle(Style.CUSTOM);
            m_game = game;
            m_parent = new Sprite();
            m_fade = new Sprite();
            m_fade.mouseChildren = true;
            m_fade.mouseEnabled = false;
            m_fade.alpha = m_fadeAlpha;
            m_sharedLvl = new SharedLevels(m_game, onStartSharedLevel, function ():void
            {
                createLevelsMenu();
            });
            var g:Graphics = m_fade.graphics;
            g.beginFill(0);
            g.drawRect(0, 0, MAX_X, BOTTOM_Y);
            g.endFill();
            parent.addChild(m_parent);
            parent.addChild(m_sharedLvl);
            parent.addChild(m_fade);
            m_sharedObj = SharedObject.getLocal("lumarama.tentacle_wars_purple_menace");
            if (m_sharedObj.data.levelsOpened == null)
            {
                m_openLevel = 1;
                m_sharedObj.data.levelsOpened = m_openLevel;
                m_sharedObj.flush(0x0100);
            }
            else
            {
                m_openLevel = m_sharedObj.data.levelsOpened;
                if (m_openLevel > 1)
                {
                    KongAPI.submitLevel((m_openLevel - 1));
                    Preloader.unlockMedal((m_openLevel - 2));
                };
            };
            fade(false);
        }

        private static function gotoUrl(url:String):void
        {
            try
            {
                navigateToURL(new URLRequest(url), "_blank");
            }
            catch(e:Error)
            {
                trace(e.message);
            };
        }

        public static function showHint(x:Number, y:Number, str:String, isCentered:Boolean=false):void
        {
            var text:TextSprite = createText(str, 12, 0xAAAAAA, 1, false, 0xFFFFFF, "translate", isCentered);
            text.x = x;
            text.y = y;
            text.name = "hint";
            m_parent.addChild(text);
            m_items.push(text);
        }

        public static function showInGameStatus(str:String, color:uint=15658666):void
        {
            var text:Sprite;
            removeByName("ingame-status");
            if (((!(str == null)) && (str.length > 0)))
            {
                text = new TypingText(("> " + str), 11, color);
                text.x = (190 + (text.width / 2));
                text.y = 15;
                text.name = "ingame-status";
                m_parent.addChild(text);
                m_items.push(text);
            };
        }

        public static function removeByName(name:String):void
        {
            var item:Sprite;
            var i:int;
            while (i < m_items.length)
            {
                item = m_items[i];
                if (item.name == name)
                {
                    item.parent.removeChild(item);
                    _SafeStr_12(item);
                    item = null;
                    m_items.splice(i, 1);
                    if (i > 0)
                    {
                        i--;
                    };
                };
                i++;
            };
        }

        private static function _SafeStr_11(dialog:Sprite, isEditor:Boolean):void
        {
            var g:Graphics = dialog.graphics;
            g.beginFill(0, 0.5);
            g.drawRect(0, (BOTTOM_Y - 30), MAX_X, 30);
            g.endFill();
            var but:DisplayObject;
            if (!isEditor)
            {
                but = new BtnRestart();
                but.scaleX = 0.7;
                but.scaleY = 0.7;
                but.x = 110;
                but.y = (BOTTOM_Y - 15);
                but.addEventListener(MouseEvent.CLICK, _SafeStr_14);
                dialog.addChild(but);
                but = new BtnPause();
                but.scaleX = 0.7;
                but.scaleY = 0.7;
                but.x = 80;
                but.y = (BOTTOM_Y - 15);
                but.addEventListener(MouseEvent.CLICK, _SafeStr_15);
                dialog.addChild(but);
            };
            var clp:MovieClip = new BtnSound();
            clp.scaleX = 0.7;
            clp.scaleY = 0.7;
            clp.x = 50;
            clp.y = (BOTTOM_Y - 15);
            clp.gotoAndStop(((m_soundOn) ? 2 : 1));
            clp.addEventListener(MouseEvent.CLICK, _SafeStr_16);
            clp.buttonMode = true;
            dialog.addChild(clp);
            but = new BtnExit();
            but.scaleX = 0.7;
            but.scaleY = 0.7;
            but.x = 20;
            but.y = (BOTTOM_Y - 15);
            but.addEventListener(MouseEvent.CLICK, onGameMenu);
            dialog.addChild(but);
            var btn:Sprite = _SafeStr_7(TXT_MORE_GAMES, (MAX_X / 2), (BOTTOM_Y - 15), _SafeStr_8);
            btn.name = GameAllianzApiLinks.TO_PORTAL_BY_MORE_GAMES;
            dialog.addChild(btn);
        }

        public static function createSaveDialog(levelData:String):void
        {
            if (levelData != null)
            {
                m_sharedLvl.submitLevel(levelData, "", "", "", function ():void
                {
                    createLevelsMenu();
                });
                return;
            };
            var win:Window = new Window(m_parent, 0, 0, ((levelData != null) ? TXT_SAVE_LEVEL : TXT_ERROR));
            win.draggable = false;
            win.width = 250;
            win.height = 100;
            win.name = "save-dialog";
            m_items.push(win);
            var vbox:VBox = new VBox(win);
            vbox.spacing = 10;
            var text:Text = new Text(vbox);
            text.height = 38;
            text.width = 250;
            text.editable = false;
            text.selectable = true;
            text.text = TXT_SUBMIT_LVL_HINT_ERROR;
            var hbox:HBox = new HBox(vbox);
            hbox.spacing = 20;
            new PushButton(hbox, 5, 0, TXT_CANCEL, function (e:MouseEvent):void
            {
                removeByName("save-dialog");
                if (levelData != null)
                {
                    m_game.initLevelEditor();
                };
            });
            hbox.x = ((win.width / 2) - (hbox.width / 2));
            win.x = ((GUI.MAX_X / 2) - (win.width / 2));
            win.y = ((GUI.MAX_Y / 2) - (win.height / 2));
        }

        public static function showEditorPanel():void
        {
            removeByName("ingame-panel");
            var dialog:Sprite = new Sprite();
            dialog.x = 0;
            dialog.y = 0;
            dialog.name = "ingame-panel";
            _SafeStr_11(dialog, true);
            var but:DisplayObject;
            but = _SafeStr_7(TXT_TEST, 0, (MAX_Y - 15), function (e:MouseEvent):void
            {
                m_game.testEditorLevel();
            });
            but.x = ((MAX_X - (but.width / 2)) - 10);
            dialog.addChild(but);
            m_parent.addChild(dialog);
            m_items.push(dialog);
        }

        private static function _SafeStr_7(str:String, x:Number, y:Number, onClick:Function, fontSize:int=14, fontName:String="translate"):Sprite
        {
            var but:Sprite = createText(str, fontSize, 0xFFFFFF, 1, false, 0xFFFFFF, fontName);
            but.mouseEnabled = true;
            but.buttonMode = true;
            but.addEventListener(MouseEvent.ROLL_OVER, _SafeStr_17);
            but.addEventListener(MouseEvent.ROLL_OUT, _SafeStr_17);
            but.addEventListener(MouseEvent.CLICK, onClick);
            but.x = x;
            but.y = y;
            return (but);
        }

        private static function _SafeStr_22(evt:MouseEvent):void
        {
            m_currLevel++;
            SoundMgr.playSfx(SoundMgr.BEGIN_GAME);
            fade(true, _SafeStr_9);
        }

        private static function onGameMenu(evt:MouseEvent=null):void
        {
            if (m_game)
            {
                m_game.clearLevel();
            };
            fade(true, createLevelsMenu);
        }

        private static function _SafeStr_18(e:MouseEvent=null):void
        {
            var spr:DisplayObject;
            while (m_fade.numChildren > 0)
            {
                spr = m_fade.getChildAt(0);
                spr.parent.removeChild(spr);
            };
            m_fade.alpha = 0;
            m_fade.mouseEnabled = false;
            m_fade.removeEventListener(MouseEvent.CLICK, _SafeStr_18);
            m_game.pause(false);
            SoundMgr.musicEnable(m_soundOn);
        }

        public static function createLevelsMenu():void
        {
            var ang:Number;
            var open:Boolean;
            var r2:Number;
            var g2:Graphics;
            var color:uint;
            var tendril:Tendril;
            removeAll();
            fade(false);
            var dialog:Sprite = _SafeStr_13();
            var top:Sprite = new Sprite();
            dialog.addChild(top);
            var g:Graphics = top.graphics;
            var r:Number = 80;
            var levelsNum:int = 20;
            var step:Number = ((Math.PI * 2) / levelsNum);
            var x:Number = (MAX_X / 2);
            var y:Number = (MAX_Y / 2);
            g.lineStyle(2, OUTLINE_COLOR);
            g.drawCircle(x, y, r);
            var but:Sprite;
            var i:int;
            while (i < levelsNum)
            {
                ang = ((i * step) - (Math.PI / 2));
                open = (i < m_openLevel);
                r2 = ((open) ? (r + 50) : (r + 25));
                g.moveTo(((Math.cos(ang) * r) + x), ((Math.sin(ang) * r) + y));
                g.lineTo(((Math.cos(ang) * r2) + x), ((Math.sin(ang) * r2) + y));
                but = _SafeStr_7(String((i + 1)), ((Math.cos(ang) * (r2 + 15)) + x), ((Math.sin(ang) * (r2 + 15)) + y), _SafeStr_19, 18, "default");
                but.name = ((open) ? String(i) : String(-1));
                g2 = but.graphics;
                g2.lineStyle(2, OUTLINE_COLOR);
                color = ((open) ? 3385907 : 11154346);
                if ((i + 1) == m_openLevel)
                {
                    color = 0x888888;
                };
                g2.beginFill(color, 0.5);
                g2.drawCircle(0, 0, 15);
                g2.endFill();
                dialog.addChild(but);
                tendril = new Tendril(((Math.random() > 0.4) ? Tendril.TYPE_WITH_SPOT : (Tendril.TYPE_WITHOUT_SPOT)), r, (((ang * 180) / Math.PI) + 10), ((Math.random() * 12) + 10), 0.05);
                tendril.setColor(((Math.random() > 0.5) ? 0 : 0x888888));
                tendril.x = x;
                tendril.y = y;
                dialog.addChild(tendril);
                i = (i + 1);
            };
            but = _SafeStr_7(TXT_EDIT, (MAX_X / 2), ((MAX_Y / 2) - 30), function (e:MouseEvent):void
            {
                m_game.initLevelEditor();
            });
            dialog.addChild(but);
            but = _SafeStr_7(TXT_SHARED_LEVELS, (MAX_X / 2), (MAX_Y / 2), function (e:MouseEvent):void
            {
                gotoUrl("http://www.gamezhero.com/games/tentaclewarsthepurplemenace/levels");
            });
            dialog.addChild(but);
            but = _SafeStr_7(TXT_ORIGINAL_GAME, (MAX_X / 2), ((MAX_Y / 2) + 30), function (e:MouseEvent):void
            {
                GameAllianzApi.getUrl("http://www.gamezhero.com/games/tentaclewars", "_blank", "tentaclewars");
            });
            dialog.addChild(but);
            m_parent.addChild(dialog);
            m_items.push(dialog);
        }

        private static function _SafeStr_13():Sprite
        {
            var clp:MovieClip;
            var dialog:Sprite = new Sprite();
            dialog.x = 0;
            dialog.y = 0;
            dialog.name = "main-menu";
            var back:Bitmap = new BmpTitleBack();
            dialog.addChild(back);
            var logo:Bitmap = new BmpSponsor();
            logo.smoothing = true;
            var logoSpr:Sprite = new Sprite();
            logoSpr.graphics.beginFill(1, 1);
            logoSpr.graphics.drawRect(0, 0, logo.width, logo.height);
            logoSpr.x = 10;
            logoSpr.y = 10;
            logoSpr.scaleX = 0.7;
            logoSpr.scaleY = 0.7;
            logoSpr.name = "http://lumarama.com/blog";
            logoSpr.buttonMode = true;
            logoSpr.addEventListener(MouseEvent.ROLL_OVER, _SafeStr_17);
            logoSpr.addEventListener(MouseEvent.ROLL_OUT, _SafeStr_17);
            logoSpr.addEventListener(MouseEvent.CLICK, _SafeStr_20);
            logoSpr.addChild(logo);
            dialog.addChild(logoSpr);
            var hdr:Sprite = createText("Tentacle Wars", 50, 0xFFFFFF, 1, true, 0, "header");
            hdr.x = (MAX_X / 2);
            hdr.y = 45;
            dialog.addChild(hdr);
            hdr = createText("Lumarama's", 14, 0xFFFFFF, 1, true, 0, "header");
            hdr.x = ((MAX_X / 2) - 153);
            hdr.y = 15;
            dialog.addChild(hdr);
            hdr = createText("The Purple Menace", 14, 11171788, 1, true, 0, "header");
            hdr.x = ((MAX_X / 2) + 123);
            hdr.y = 15;
            dialog.addChild(hdr);
            var btn1:Sprite = new AssetPortalLogo(dialog, ((MAX_X / 2) - 90), (BOTTOM_Y - 70), 0.6);
            var btn2:Sprite = new AssetFacebookButton(dialog, (MAX_X - 60), (BOTTOM_Y - 60), 0.5);
            var btn3:Sprite = new AssetTwitterButton(dialog, 20, (BOTTOM_Y - 60), 0.5);
            clp = new BtnSound();
            clp.x = (MAX_X - 30);
            clp.y = 30;
            clp.gotoAndStop(((m_soundOn) ? 2 : 1));
            clp.addEventListener(MouseEvent.CLICK, _SafeStr_16);
            clp.buttonMode = true;
            dialog.addChild(clp);
            return (dialog);
        }

        public static function createInterLevelMenu(isLevelPassed:Boolean, time:int, achieve:Achievements):void
        {
            var delta:int;
            var ngPopup:MedalPopup;
            m_currScore = achieve.getScore();
            if (isLevelPassed)
            {
                if ((m_currLevel + 2) > m_openLevel)
                {
                    delta = (100 - time);
                    if (delta < 5)
                    {
                        delta = 5;
                    };
                    achieve.addScore(delta);
                    m_openLevel = (m_currLevel + 2);
                    m_sharedObj.data.levelsOpened = m_openLevel;
                    m_sharedObj.flush(0x0100);
                    m_successTries++;
                    API.unlockMedal((("Level " + ((m_openLevel > 10) ? "" : "0")) + (m_openLevel - 1)));
                    ngPopup = new MedalPopup();
                    ngPopup.x = ((MAX_X / 2) - (ngPopup.width / 2));
                    ngPopup.y = 8;
                    m_parent.stage.addChild(ngPopup);
                };
                m_currScore = achieve.getScore();
                if (m_openLevel > 1)
                {
                    KongAPI.submitLevel((m_openLevel - 1));
                    KongAPI.submitHighScore(m_currScore);
                    Preloader.sendTemporaryScore(0, m_currScore);
                    Preloader.unlockMedal((m_openLevel - 2));
                };
                if ((m_currLevel + 2) > 20)
                {
                    createFinalScreen();
                    return;
                };
            }
            else
            {
                if ((m_currLevel + 1) == m_openLevel)
                {
                    m_totalTries++;
                };
            };
            if (((m_currLevel == 5) && (time <= 40)))
            {
                m_game.newAchievement(Achievements.ID_FAST_VICTORY);
            };
            if (((m_successTries >= 10) && (m_totalTries <= (m_successTries * 2))))
            {
                m_game.newAchievement(Achievements.ID_MIN_FAILS);
            };
            SoundMgr.playSfx(((isLevelPassed) ? SoundMgr.LEVEL_PASSED : SoundMgr.LEVEL_FAILED));
            var dialog:Sprite = _SafeStr_21(isLevelPassed, time);
            dialog.name = "inter-level";
            var but:Sprite;
            var timeScore:String = ((((((TXT_TIME + ": ") + time) + "    ") + TXT_SCORE) + ": ") + m_currScore);
            var timeSpr:Sprite = createText(timeScore.toUpperCase(), 14, 15658666, 1, false, 0xFFFFFF, "translate", true);
            timeSpr.x = 0;
            timeSpr.y = -45;
            dialog.addChild(timeSpr);
            if (isLevelPassed)
            {
                but = _SafeStr_7(TXT_SUBMIT_SCORE, 0, -25, onSubmitScoreClick);
                dialog.addChild(but);
            };
            if (isLevelPassed)
            {
                but = _SafeStr_7(TXT_MORE_GAMES, 0, 120, _SafeStr_8);
                but.name = GameAllianzApiLinks.TO_PORTAL_BY_MORE_GAMES;
            }
            else
            {
                but = _SafeStr_7(TXT_WALKTHROUGH, 0, 120, _SafeStr_8);
                but.name = GameAllianzApiLinks.TO_GAME_WALKTHROUGH;
            };
            dialog.addChild(but);
            if (isLevelPassed)
            {
                but = _SafeStr_7(TXT_CONTINUE, 0, 150, _SafeStr_22);
            }
            else
            {
                but = _SafeStr_7(TXT_REPLAY, 0, 150, _SafeStr_14);
            };
            dialog.addChild(but);
            m_parent.addChild(dialog);
            m_items.push(dialog);
        }

        private static function _SafeStr_15(e:MouseEvent=null):void
        {
            m_fade.alpha = 0.7;
            m_fade.mouseEnabled = true;
            m_fade.addEventListener(MouseEvent.CLICK, _SafeStr_18);
            m_game.pause(true);
            SoundMgr.musicEnable(false);
            var pause:Sprite = createText("PAUSED", 50, 0xFFFFFF, 1, true, 0, "header");
            pause.x = (MAX_X / 2);
            pause.y = (MAX_Y / 2);
            pause.mouseEnabled = false;
            m_fade.addChild(pause);
        }

        private static function _SafeStr_12(item:Sprite):void
        {
            var tendril:Tendril;
            var text:TypingText;
            var cell:Cell;
            if ((item is Tendril))
            {
                tendril = (item as Tendril);
                tendril.destruct();
                tendril = null;
            }
            else
            {
                if ((item is TypingText))
                {
                    text = (item as TypingText);
                    text.destruct();
                    text = null;
                }
                else
                {
                    if ((item is Cell))
                    {
                        cell = (item as Cell);
                        cell.destruct();
                        cell = null;
                    };
                };
            };
        }

        public static function startSharedLevelById(levelId:String):void
        {
            m_sharedLvl.getLevel(levelId, "");
        }

        private static function replayLevel():void
        {
            if (m_currLevel >= 0)
            {
                if (m_game)
                {
                    removeAll();
                    m_game.replayLevel();
                };
            };
            fade(false);
        }

        private static function _SafeStr_8(event:MouseEvent):void
        {
            var but:DisplayObject = (event.target as DisplayObject);
            if (((!(but == null)) && (but.name.length > 0)))
            {
                GameAllianzApi.navigateTo(but.name);
            };
        }


    }
}//package 

// _SafeStr_10 = "_-54" (String#4891, DoABC#2)
// _SafeStr_11 = "_-C5" (String#5231, DoABC#2)
// _SafeStr_12 = "_-Br" (String#5218, DoABC#2)
// _SafeStr_13 = "_-6n" (String#4975, DoABC#2)
// _SafeStr_14 = "_-A" (String#5128, DoABC#2)
// _SafeStr_15 = "_-h" (String#5289, DoABC#2)
// _SafeStr_16 = "_-1T" (String#4723, DoABC#2)
// _SafeStr_17 = "_-0m" (String#4689, DoABC#2)
// _SafeStr_18 = "_-6U" (String#4961, DoABC#2)
// _SafeStr_19 = "_-5P" (String#4906, DoABC#2)
// _SafeStr_20 = "_-AC" (String#5141, DoABC#2)
// _SafeStr_21 = "_-4o" (String#4878, DoABC#2)
// _SafeStr_22 = "_-8Z" (String#5060, DoABC#2)
// _SafeStr_7 = "_-22" (String#4752, DoABC#2)
// _SafeStr_8 = "_-7P" (String#5004, DoABC#2)
// _SafeStr_9 = "in " (String#6552, DoABC#2)


